package com.ruoyi.baseCate.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.baseCate.domain.BaseCate;
import com.ruoyi.baseCate.service.IBaseCateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 基地分类Controller
 * 
 * @author shz
 * @date 2024-08-10
 */
@RestController
@RequestMapping("/baseCate/baseCate")
public class BaseCateController extends BaseController
{
    @Autowired
    private IBaseCateService baseCateService;

    /**
     * 查询基地分类列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BaseCate baseCate)
    {
        startPage();
        List<BaseCate> list = baseCateService.selectBaseCateList(baseCate);
        return getDataTable(list);
    }

    /**
     * 导出基地分类列表
     */
    @Log(title = "基地分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseCate baseCate)
    {
        List<BaseCate> list = baseCateService.selectBaseCateList(baseCate);
        ExcelUtil<BaseCate> util = new ExcelUtil<BaseCate>(BaseCate.class);
        util.exportExcel(response, list, "基地分类数据");
    }

    /**
     * 获取基地分类详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseCateService.selectBaseCateById(id));
    }

    /**
     * 新增基地分类
     */
    @Log(title = "基地分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseCate baseCate)
    {
        return toAjax(baseCateService.insertBaseCate(baseCate));
    }

    /**
     * 修改基地分类
     */
    @Log(title = "基地分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseCate baseCate)
    {
        return toAjax(baseCateService.updateBaseCate(baseCate));
    }

    /**
     * 删除基地分类
     */
    @Log(title = "基地分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseCateService.deleteBaseCateByIds(ids));
    }
}
